<template>
	<view class="container">
			<view class="example">
				<uni-forms ref="baseForm" :modelValue="baseFormData" :rules="rules">
					<uni-forms-item label="联系人" required name="addrContact">
						<uni-easyinput type="text" v-model="baseFormData.addrContact" placeholder="请输入姓名" />
					</uni-forms-item>
					<uni-forms-item label="联系电话" required name="addrPhone">
						<uni-easyinput type="text" v-model="baseFormData.addrPhone" placeholder="请输入联系方式" />
					</uni-forms-item>
					<uni-forms-item label="性别" required name="userSex">
						<uni-data-checkbox v-model="baseFormData.userSex" :localdata="sexs" />
					</uni-forms-item>
					<uni-forms-item label="详细地址" required name="addrContent">
						<uni-easyinput type="textarea" v-model="baseFormData.addrContent" placeholder="请输入您的地址" />
					</uni-forms-item>
					
				</uni-forms>
			</view>
			<view style="display: flex; justify-content: space-between;">
				<button class="button" @click="submit1()">提交</button>
				<button class="button" @click="cancel1()">取消</button>
			</view>
			

	</view>
</template>
<script>
	export default {
		data() {
			return {
				// 基础表单数据
				baseFormData:{
					userId:'',
					addrId:'',
					addrContact:'',
					userSex:'',
					addrPhone:'',
					addrContent:''
				},
				rules: {
					addrContact: {
						rules: [{
							required: true,
							errorMessage: '姓名不能为空'
						}]
					},
					addrPhone: {
						rules: [{
							required: true,
							errorMessage: '手机号'
						}, {
							format: 'number',
							errorMessage: '手机号只能是数字'
						},
						]
					},
					userSex: {
						rules: [{
							required: true,
							errorMessage: '请勾选性别'
						}]
					},
					addrContent:{
						rules: [{
							required: true,
							errorMessage: '请填写地址'
						}]
					}
					
					
				},
				// 单选数据源
				sexs: [{
					text: '男',
					value: 0
				}, {
					text: '女',
					value: 1
				}, {
					text: '保密',
					value: 2
				}],
			}
		},

		onLoad(options) {
			
			
			console.log(this.baseFormData)
		},
		methods: {
			submit1(){
				console.log(this.baseFormData)
				
				 this.$refs.baseForm.validate().then(res => {
								uni.hideLoading()
								this.request({
									url:"/base-position",
									method:'PUT',
									data:this.baseFormData
								
								}).then(res=>{
									if(res.code==='1'){
										uni.navigateTo({
											url:'/pages/my_positon/my_positon'
										})
										console.log("成功")
										}
									
									else{
										console.log("失败")
									}
								}).catch(()=>{
									console.log("系统错误")
								})
									//uni.navigateBack()
								
							}).catch(err => {
								uni.hideLoading()
								console.log('表单错误信息：', err);
								return 
							})
							
						},
			cancel1(){
				//uni.navigateBack()
			}
	
	},
	}
</script>
<style lang="scss">

	.example {
		padding: 15px;
		background-color: #fff;
	}

	.segmented-control {
		margin-bottom: 15px;
	}

	.button-group {
		margin-top: 15px;
		display: flex;
		justify-content: space-around;
	}

	.form-item {
		display: flex;
		align-items: center;
	}

	.button {
		display: flex;
		background-color: #2979FF;
		align-items: center;
		justify-content: center;
		width: 200rpx;
		height: 80rpx;
		color: #fff;
		font-size: 28rpx;
	}
</style>
